using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace sharpTV.Entities
{
	/// <summary>
	/// Strongly-typed collection for the Spot class.
	/// </summary>
    [Serializable]
	public partial class SpotCollection : ActiveList<Spot, SpotCollection>
	{	   
		public SpotCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>SpotCollection</returns>
		public SpotCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Spot o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the sharpTV_Spots table.
	/// </summary>
	[Serializable]
	public partial class Spot : ActiveRecord<Spot>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Spot()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Spot(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Spot(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Spot(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("sharpTV_Spots", TableType.Table, DataService.GetInstance("sharpTVSubSonicProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarSpotId = new TableSchema.TableColumn(schema);
				colvarSpotId.ColumnName = "SpotId";
				colvarSpotId.DataType = DbType.Int32;
				colvarSpotId.MaxLength = 0;
				colvarSpotId.AutoIncrement = true;
				colvarSpotId.IsNullable = false;
				colvarSpotId.IsPrimaryKey = true;
				colvarSpotId.IsForeignKey = false;
				colvarSpotId.IsReadOnly = false;
				colvarSpotId.DefaultSetting = @"";
				colvarSpotId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSpotId);
				
				TableSchema.TableColumn colvarSpotUId = new TableSchema.TableColumn(schema);
				colvarSpotUId.ColumnName = "SpotUId";
				colvarSpotUId.DataType = DbType.Guid;
				colvarSpotUId.MaxLength = 0;
				colvarSpotUId.AutoIncrement = false;
				colvarSpotUId.IsNullable = true;
				colvarSpotUId.IsPrimaryKey = false;
				colvarSpotUId.IsForeignKey = false;
				colvarSpotUId.IsReadOnly = false;
				
						colvarSpotUId.DefaultSetting = @"(newid())";
				colvarSpotUId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSpotUId);
				
				TableSchema.TableColumn colvarCompanyName = new TableSchema.TableColumn(schema);
				colvarCompanyName.ColumnName = "CompanyName";
				colvarCompanyName.DataType = DbType.String;
				colvarCompanyName.MaxLength = 256;
				colvarCompanyName.AutoIncrement = false;
				colvarCompanyName.IsNullable = true;
				colvarCompanyName.IsPrimaryKey = false;
				colvarCompanyName.IsForeignKey = false;
				colvarCompanyName.IsReadOnly = false;
				colvarCompanyName.DefaultSetting = @"";
				colvarCompanyName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompanyName);
				
				TableSchema.TableColumn colvarName = new TableSchema.TableColumn(schema);
				colvarName.ColumnName = "Name";
				colvarName.DataType = DbType.String;
				colvarName.MaxLength = 1024;
				colvarName.AutoIncrement = false;
				colvarName.IsNullable = true;
				colvarName.IsPrimaryKey = false;
				colvarName.IsForeignKey = false;
				colvarName.IsReadOnly = false;
				
						colvarName.DefaultSetting = @"(N'')";
				colvarName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarName);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = 3000;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = true;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				
						colvarDescription.DefaultSetting = @"(N'')";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				TableSchema.TableColumn colvarMediaSourceId = new TableSchema.TableColumn(schema);
				colvarMediaSourceId.ColumnName = "MediaSourceId";
				colvarMediaSourceId.DataType = DbType.Int32;
				colvarMediaSourceId.MaxLength = 0;
				colvarMediaSourceId.AutoIncrement = false;
				colvarMediaSourceId.IsNullable = true;
				colvarMediaSourceId.IsPrimaryKey = false;
				colvarMediaSourceId.IsForeignKey = false;
				colvarMediaSourceId.IsReadOnly = false;
				colvarMediaSourceId.DefaultSetting = @"";
				colvarMediaSourceId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaSourceId);
				
				TableSchema.TableColumn colvarCreationDate = new TableSchema.TableColumn(schema);
				colvarCreationDate.ColumnName = "CreationDate";
				colvarCreationDate.DataType = DbType.DateTime;
				colvarCreationDate.MaxLength = 0;
				colvarCreationDate.AutoIncrement = false;
				colvarCreationDate.IsNullable = true;
				colvarCreationDate.IsPrimaryKey = false;
				colvarCreationDate.IsForeignKey = false;
				colvarCreationDate.IsReadOnly = false;
				
						colvarCreationDate.DefaultSetting = @"(getdate())";
				colvarCreationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreationDate);
				
				TableSchema.TableColumn colvarOwner = new TableSchema.TableColumn(schema);
				colvarOwner.ColumnName = "Owner";
				colvarOwner.DataType = DbType.Guid;
				colvarOwner.MaxLength = 0;
				colvarOwner.AutoIncrement = false;
				colvarOwner.IsNullable = true;
				colvarOwner.IsPrimaryKey = false;
				colvarOwner.IsForeignKey = false;
				colvarOwner.IsReadOnly = false;
				colvarOwner.DefaultSetting = @"";
				colvarOwner.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOwner);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sharpTVSubSonicProvider"].AddSchema("sharpTV_Spots",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("SpotId")]
		[Bindable(true)]
		public int SpotId 
		{
			get { return GetColumnValue<int>(Columns.SpotId); }
			set { SetColumnValue(Columns.SpotId, value); }
		}
		  
		[XmlAttribute("SpotUId")]
		[Bindable(true)]
		public Guid? SpotUId 
		{
			get { return GetColumnValue<Guid?>(Columns.SpotUId); }
			set { SetColumnValue(Columns.SpotUId, value); }
		}
		  
		[XmlAttribute("CompanyName")]
		[Bindable(true)]
		public string CompanyName 
		{
			get { return GetColumnValue<string>(Columns.CompanyName); }
			set { SetColumnValue(Columns.CompanyName, value); }
		}
		  
		[XmlAttribute("Name")]
		[Bindable(true)]
		public string Name 
		{
			get { return GetColumnValue<string>(Columns.Name); }
			set { SetColumnValue(Columns.Name, value); }
		}
		  
		[XmlAttribute("Description")]
		[Bindable(true)]
		public string Description 
		{
			get { return GetColumnValue<string>(Columns.Description); }
			set { SetColumnValue(Columns.Description, value); }
		}
		  
		[XmlAttribute("MediaSourceId")]
		[Bindable(true)]
		public int? MediaSourceId 
		{
			get { return GetColumnValue<int?>(Columns.MediaSourceId); }
			set { SetColumnValue(Columns.MediaSourceId, value); }
		}
		  
		[XmlAttribute("CreationDate")]
		[Bindable(true)]
		public DateTime? CreationDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.CreationDate); }
			set { SetColumnValue(Columns.CreationDate, value); }
		}
		  
		[XmlAttribute("Owner")]
		[Bindable(true)]
		public Guid? Owner 
		{
			get { return GetColumnValue<Guid?>(Columns.Owner); }
			set { SetColumnValue(Columns.Owner, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid? varSpotUId,string varCompanyName,string varName,string varDescription,int? varMediaSourceId,DateTime? varCreationDate,Guid? varOwner)
		{
			Spot item = new Spot();
			
			item.SpotUId = varSpotUId;
			
			item.CompanyName = varCompanyName;
			
			item.Name = varName;
			
			item.Description = varDescription;
			
			item.MediaSourceId = varMediaSourceId;
			
			item.CreationDate = varCreationDate;
			
			item.Owner = varOwner;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varSpotId,Guid? varSpotUId,string varCompanyName,string varName,string varDescription,int? varMediaSourceId,DateTime? varCreationDate,Guid? varOwner)
		{
			Spot item = new Spot();
			
				item.SpotId = varSpotId;
			
				item.SpotUId = varSpotUId;
			
				item.CompanyName = varCompanyName;
			
				item.Name = varName;
			
				item.Description = varDescription;
			
				item.MediaSourceId = varMediaSourceId;
			
				item.CreationDate = varCreationDate;
			
				item.Owner = varOwner;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn SpotIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn SpotUIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn CompanyNameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn NameColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn DescriptionColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn MediaSourceIdColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn CreationDateColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn OwnerColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string SpotId = @"SpotId";
			 public static string SpotUId = @"SpotUId";
			 public static string CompanyName = @"CompanyName";
			 public static string Name = @"Name";
			 public static string Description = @"Description";
			 public static string MediaSourceId = @"MediaSourceId";
			 public static string CreationDate = @"CreationDate";
			 public static string Owner = @"Owner";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
